package com.zh.common.view

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.SizeUtils
import com.zh.common.R

/**
 * 自定义空页面
 */
class XEmptyView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private val view = inflate(context, R.layout.viewstatus_no_data, this)
    private val tvContent = view.findViewById<TextView>(R.id.tv_content)
    private val ivImg = view.findViewById<ImageView>(R.id.iv_img)

    fun setTextDesc(desc: String) {
        view.findViewById<TextView>(R.id.tv_content).text = desc
    }

    fun setTextSize(size: Float) {
        tvContent.textSize = SizeUtils.px2sp(size).toFloat()
    }

    fun setTextColor(color: Int) {
        tvContent.setTextColor(ContextCompat.getColor(context, color))
    }

    fun setImage(resId: Int) {
        ivImg.setImageResource(resId)
    }

    fun setImageSize(width: Int, height: Int) {
        ivImg.layoutParams.width = width
        ivImg.layoutParams.height = height
    }
}